1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.MarkAttributes;
26 
27 private import gdk.PaintableIF;
28 private import gdk.RGBA;
29 private import gdkpixbuf.Pixbuf;
30 private import gio.IconIF;
31 private import glib.ConstructionException;
32 private import glib.MemorySlice;
33 private import glib.Str;
34 private import glib.c.functions;
35 private import gobject.ObjectG;
36 private import gobject.Signals;
37 private import gtk.Widget;
38 private import sourceview.Mark;
39 private import sourceview.c.functions;
40 public  import sourceview.c.types;
41 private import std.algorithm;
42 
43 
44 /**
45  * The source mark attributes object.
46  * 
47  * `GtkSourceMarkAttributes` is an object specifying attributes used by
48  * a [class@View] to visually show lines marked with [class@Mark]s
49  * of a specific category. It allows you to define a background color of a line,
50  * an icon shown in gutter and tooltips.
51  * 
52  * The background color is used as a background of a line where a mark is placed
53  * and it can be set with [method@MarkAttributes.set_background]. To check
54  * if any custom background color was defined and what color it is, use
55  * [method@MarkAttributes.get_background].
56  * 
57  * An icon is a graphic element which is shown in the gutter of a view. An
58  * example use is showing a red filled circle in a debugger to show that a
59  * breakpoint was set in certain line. To get an icon that will be placed in
60  * a gutter, first a base for it must be specified and then
61  * [method@MarkAttributes.render_icon] must be called.
62  * There are several ways to specify a base for an icon:
63  * 
64  * - [method@MarkAttributes.set_icon_name]
65  * - [method@MarkAttributes.set_gicon]
66  * - [method@MarkAttributes.set_pixbuf]
67  * 
68  * Using any of the above functions overrides the one used earlier. But note
69  * that a getter counterpart of earlier used function can still return some
70  * value, but it is just not used when rendering the proper icon.
71  * 
72  * To provide meaningful tooltips for a given mark of a category, you should
73  * connect to [signal@MarkAttributes::query-tooltip-text] or
74  * [signal@MarkAttributes::query-tooltip-markup] where the latter
75  * takes precedence.
76  */
77 public class MarkAttributes : ObjectG
78 {
79 	/** the main Gtk struct */
80 	protected GtkSourceMarkAttributes* gtkSourceMarkAttributes;
81 
82 	/** Get the main Gtk struct */
83 	public GtkSourceMarkAttributes* getMarkAttributesStruct(bool transferOwnership = false)
84 	{
85 		if (transferOwnership)
86 			ownedRef = false;
87 		return gtkSourceMarkAttributes;
88 	}
89 
90 	/** the main Gtk struct as a void* */
91 	protected override void* getStruct()
92 	{
93 		return cast(void*)gtkSourceMarkAttributes;
94 	}
95 
96 	/**
97 	 * Sets our main struct and passes it to the parent class.
98 	 */
99 	public this (GtkSourceMarkAttributes* gtkSourceMarkAttributes, bool ownedRef = false)
100 	{
101 		this.gtkSourceMarkAttributes = gtkSourceMarkAttributes;
102 		super(cast(GObject*)gtkSourceMarkAttributes, ownedRef);
103 	}
104 
105 
106 	/** */
107 	public static GType getType()
108 	{
109 		return gtk_source_mark_attributes_get_type();
110 	}
111 
112 	/**
113 	 * Creates a new source mark attributes.
114 	 *
115 	 * Returns: a new source mark attributes.
116 	 *
117 	 * Throws: ConstructionException GTK+ fails to create the object.
118 	 */
119 	public this()
120 	{
121 		auto __p = gtk_source_mark_attributes_new();
122 
123 		if(__p is null)
124 		{
125 			throw new ConstructionException("null returned by new");
126 		}
127 
128 		this(cast(GtkSourceMarkAttributes*) __p, true);
129 	}
130 
131 	/**
132 	 * Stores background color in @background.
133 	 *
134 	 * Params:
135 	 *     background = a #GdkRGBA.
136 	 *
137 	 * Returns: whether background color for @attributes was set.
138 	 */
139 	public bool getBackground(out RGBA background)
140 	{
141 		GdkRGBA* outbackground = sliceNew!GdkRGBA();
142 
143 		auto __p = gtk_source_mark_attributes_get_background(gtkSourceMarkAttributes, outbackground) != 0;
144 
145 		background = ObjectG.getDObject!(RGBA)(outbackground, true);
146 
147 		return __p;
148 	}
149 
150 	/**
151 	 * Gets a [iface@Gio.Icon] to be used as a base for rendered icon.
152 	 *
153 	 * Note that the icon can be %NULL if it wasn't set earlier.
154 	 *
155 	 * Returns: An icon. The icon belongs to @attributes and should
156 	 *     not be unreffed.
157 	 */
158 	public IconIF getGicon()
159 	{
160 		auto __p = gtk_source_mark_attributes_get_gicon(gtkSourceMarkAttributes);
161 
162 		if(__p is null)
163 		{
164 			return null;
165 		}
166 
167 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p);
168 	}
169 
170 	/**
171 	 * Gets a name of an icon to be used as a base for rendered icon.
172 	 *
173 	 * Note that the icon name can be %NULL if it wasn't set earlier.
174 	 *
175 	 * Returns: An icon name. The string belongs to @attributes and
176 	 *     should not be freed.
177 	 */
178 	public string getIconName()
179 	{
180 		return Str.toString(gtk_source_mark_attributes_get_icon_name(gtkSourceMarkAttributes));
181 	}
182 
183 	/**
184 	 * Gets a [class@GdkPixbuf.Pixbuf] to be used as a base for rendered icon.
185 	 *
186 	 * Note that the pixbuf can be %NULL if it wasn't set earlier.
187 	 *
188 	 * Returns: A pixbuf. The pixbuf belongs to @attributes and
189 	 *     should not be unreffed.
190 	 */
191 	public Pixbuf getPixbuf()
192 	{
193 		auto __p = gtk_source_mark_attributes_get_pixbuf(gtkSourceMarkAttributes);
194 
195 		if(__p is null)
196 		{
197 			return null;
198 		}
199 
200 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p);
201 	}
202 
203 	/**
204 	 * Queries for a tooltip by emitting a [signal@MarkAttributes::query-tooltip-markup] signal.
205 	 *
206 	 * The tooltip may contain a markup.
207 	 *
208 	 * Params:
209 	 *     mark = a #GtkSourceMark.
210 	 *
211 	 * Returns: A tooltip. The returned string should be freed by
212 	 *     using g_free() when done with it.
213 	 */
214 	public string getTooltipMarkup(Mark mark)
215 	{
216 		auto retStr = gtk_source_mark_attributes_get_tooltip_markup(gtkSourceMarkAttributes, (mark is null) ? null : mark.getMarkStruct());
217 
218 		scope(exit) Str.freeString(retStr);
219 		return Str.toString(retStr);
220 	}
221 
222 	/**
223 	 * Queries for a tooltip by emitting a [signal@MarkAttributes::query-tooltip-text] signal.
224 	 *
225 	 * The tooltip is a plain text.
226 	 *
227 	 * Params:
228 	 *     mark = a #GtkSourceMark.
229 	 *
230 	 * Returns: A tooltip. The returned string should be freed by
231 	 *     using g_free() when done with it.
232 	 */
233 	public string getTooltipText(Mark mark)
234 	{
235 		auto retStr = gtk_source_mark_attributes_get_tooltip_text(gtkSourceMarkAttributes, (mark is null) ? null : mark.getMarkStruct());
236 
237 		scope(exit) Str.freeString(retStr);
238 		return Str.toString(retStr);
239 	}
240 
241 	/**
242 	 * Renders an icon of given size.
243 	 *
244 	 * The base of the icon is set by the last call to one of:
245 	 *
246 	 * - [method@MarkAttributes.set_pixbuf]
247 	 * - [method@MarkAttributes.set_gicon]
248 	 * - [method@MarkAttributes.set_icon_name]
249 	 *
250 	 * @size cannot be lower than 1.
251 	 *
252 	 * Params:
253 	 *     widget = widget of which style settings may be used.
254 	 *     size = size of the rendered icon.
255 	 *
256 	 * Returns: A #GdkPaintable. The paintable belongs to @attributes
257 	 *     and should not be unreffed.
258 	 */
259 	public PaintableIF renderIcon(Widget widget, int size)
260 	{
261 		auto __p = gtk_source_mark_attributes_render_icon(gtkSourceMarkAttributes, (widget is null) ? null : widget.getWidgetStruct(), size);
262 
263 		if(__p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p);
269 	}
270 
271 	/**
272 	 * Sets background color to the one given in @background.
273 	 *
274 	 * Params:
275 	 *     background = a #GdkRGBA.
276 	 */
277 	public void setBackground(RGBA background)
278 	{
279 		gtk_source_mark_attributes_set_background(gtkSourceMarkAttributes, (background is null) ? null : background.getRGBAStruct());
280 	}
281 
282 	/**
283 	 * Sets an icon to be used as a base for rendered icon.
284 	 *
285 	 * Params:
286 	 *     gicon = a #GIcon to be used.
287 	 */
288 	public void setGicon(IconIF gicon)
289 	{
290 		gtk_source_mark_attributes_set_gicon(gtkSourceMarkAttributes, (gicon is null) ? null : gicon.getIconStruct());
291 	}
292 
293 	/**
294 	 * Sets a name of an icon to be used as a base for rendered icon.
295 	 *
296 	 * Params:
297 	 *     iconName = name of an icon to be used.
298 	 */
299 	public void setIconName(string iconName)
300 	{
301 		gtk_source_mark_attributes_set_icon_name(gtkSourceMarkAttributes, Str.toStringz(iconName));
302 	}
303 
304 	/**
305 	 * Sets a pixbuf to be used as a base for rendered icon.
306 	 *
307 	 * Params:
308 	 *     pixbuf = a #GdkPixbuf to be used.
309 	 */
310 	public void setPixbuf(Pixbuf pixbuf)
311 	{
312 		gtk_source_mark_attributes_set_pixbuf(gtkSourceMarkAttributes, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
313 	}
314 
315 	/**
316 	 * The code should connect to this signal to provide a tooltip for given
317 	 * @mark. The tooltip can contain a markup.
318 	 *
319 	 * Params:
320 	 *     mark = The #GtkSourceMark.
321 	 *
322 	 * Returns: A tooltip. The string should be freed with
323 	 *     g_free() when done with it.
324 	 */
325 	gulong addOnQueryTooltipMarkup(string delegate(Mark, MarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
326 	{
327 		return Signals.connect(this, "query-tooltip-markup", dlg, connectFlags ^ ConnectFlags.SWAPPED);
328 	}
329 
330 	/**
331 	 * The code should connect to this signal to provide a tooltip for given
332 	 * @mark. The tooltip should be just a plain text.
333 	 *
334 	 * Params:
335 	 *     mark = The #GtkSourceMark.
336 	 *
337 	 * Returns: A tooltip. The string should be freed with
338 	 *     g_free() when done with it.
339 	 */
340 	gulong addOnQueryTooltipText(string delegate(Mark, MarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
341 	{
342 		return Signals.connect(this, "query-tooltip-text", dlg, connectFlags ^ ConnectFlags.SWAPPED);
343 	}
344 }